package com.csdj.sc.common.base;

import com.csdj.sc.common.util.MessageUtil;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * 返回给前端的统一数据结构
 */
public class WebResult {

    private int code;
    private String msg;
    private Map<String,Object> result = new HashMap<>();

    public WebResult(){}

    public WebResult(int code){
        this.code = code;
        this.msg = MessageUtil.getMsg(code);
    }

    public WebResult(int code,Locale locale,Object data){
        this.code = code;
        this.msg = MessageUtil.getMsg(code,locale);
        this.result.put("data",data);
    }

    public WebResult(int code,Locale locale){
        this.code = code;
        this.msg = MessageUtil.getMsg(code,locale);
    }

    public WebResult(int code,Object data){
        this.code = code;
        this.msg = MessageUtil.getMsg(code);
        this.result.put("data",data);
    }

    public WebResult putData(String key,Object data){
        this.result.put(key,data);
        return this;
    }





    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getResult() {
        return result;
    }

    public void setResult(Map<String, Object> result) {
        this.result = result;
    }
}
